package Algorithm.LinkList;

public class LinkList3 {
    public ListNode removeElements(ListNode head, int val) {

        if(head == null) { return null; }

        ListNode res = removeElements(head.next, val);
        if(head.val == val){
            return res;
        }else {
            head.next = res;
            return head;
        }
//        head.next = removeElements(head.next, val);
//        return head.val == val ? head.next:head;
    }
    public static void main(String[] args) {
        int[] nums = {1,3,2,7,9,4};
        ListNode listNode = new ListNode(nums);
        System.out.println(listNode);
        ListNode listNode1 = new LinkList3().removeElements(listNode, 1);
        System.out.println(listNode1);
        }
}
